import queue

class Crossing2():
    def __init__(self, lukou_ID=0, t_green=0, t_red=0, delta_t_g_max=0, delta_t_r_max=0, l1=0, l2=0, brt_time=1, other_time=1, delta_t=0,
                 v_bus=35, v_bus_max=100, M=20,
                 mainflag=True, green_long_flag=False, red_short_flag=False, speed_flag=False):
        self.lukou_ID = lukou_ID
        self.t_green = t_green
        self.t_red = t_red
        self.delta_t_g_max = delta_t_g_max
        self.delta_t_r_max = delta_t_r_max
        self.l1 = l1
        self.l2 = l2
        self.brt_time = brt_time
        self.other_time = other_time
        self.delta_t = delta_t
        self.v_bus = v_bus
        self.v_bus_max = v_bus_max
        self.mainflag = mainflag
        self.green_long_flag = green_long_flag
        self.red_short_flag = red_short_flag
        self.speed_flag = speed_flag

        self.q1 = 0
        self.q2 = 0

        ''' v2.0 new '''
        self.queue1 = queue.Queue(maxsize=0)  # 不限制队列长度
        self.queue2 = queue.Queue(maxsize=0)
        self.queue3 = queue.Queue(maxsize=0)
        self.queue4 = queue.Queue(maxsize=0)

        self.duilie1 = 0
        self.duilie2 = 0
        self.duilie3 = 0
        self.M = M  # duilie表示Q，M为乘客数量

        for i in range(40):  # 初始队列长度为40
            self.queue1.put(0)
            self.queue2.put(0)
        ''' new end '''

    def Set2(self):
        self.l1 = self.v_bus / 3.6 * self.delta_t_g_max  # 检测器1与路口停车线的距离
        self.l2 = self.v_bus * self.v_bus_max / (self.v_bus_max - self.v_bus) / 3.6 * (
                    self.t_red - self.delta_t_g_max - self.delta_t_r_max) + self.l1  # c检测器2与路口停车线的距离


class Crossing4():
    # time_1、2、3、4分别记录四个相位当前绿灯持续的时间
    def __init__(self, lukou_ID=0, t_g_1=0, t_g_2=0, t_g_3=0, t_g_4=0, delta_t_g_max=0, delta_t_r_max=0, l1=0, l2=0, T=0,
                 time_1=1, time_2=1, time_3=1, time_4=1, delta_t=0, main_flag=1,
                 v_bus=35, v_bus_max=100,
                 green_long_flag=False, red_short_flag=False, speed_flag=False):
        self.lukou_ID = lukou_ID
        self.t_g_1 = t_g_1
        self.t_g_2 = t_g_2
        self.t_g_3 = t_g_3
        self.t_g_4 = t_g_4
        self.delta_t_g_max = delta_t_g_max
        self.delta_t_r_max = delta_t_r_max
        self.l1 = l1
        self.l2 = l2
        self.T = T
        self.time_1 = time_1
        self.time_2 = time_2
        self.time_3 = time_3
        self.time_4 = time_4
        self.delta_t = delta_t
        self.main_flag = main_flag
        self.v_bus = v_bus
        self.v_bus_max = v_bus_max
        self.green_long_flag = green_long_flag
        self.red_short_flag = red_short_flag
        self.speed_flag = speed_flag

        # new_3
        self.queue1 = queue.Queue(maxsize=0)  # 不限制队列长度
        self.queue2 = queue.Queue(maxsize=0)
        self.queue3 = queue.Queue(maxsize=0)  # 不限制队列长度
        self.queue4 = queue.Queue(maxsize=0)

        self.v_bus = 35
        self.v_bus_max = 100
        self.r1, self.r2, self.r3, self.r4 = 0, 0, 0, 0   # r为四个相位的转向
        self.q1, self.q2, self.q3, self.q4 = 0, 0, 0, 0  # 车流量
        self.T = 0
        self.M = 20

        for i in range(60):  # 初始队列长度为40
            self.queue1.put(0)
            self.queue2.put(0)
            self.queue3.put(0)
            self.queue4.put(0)

    def Set4(self):
        self.l1 = self.v_bus / 3.6 * self.delta_t_g_max
        self.l2 = self.v_bus * self.v_bus_max / (self.v_bus_max - self.v_bus) / 3.6 * (
                    self.t_g_2 + self.t_g_3 + self.t_g_4 + -self.delta_t_g_max - self.delta_t_r_max) + self.l1  # 与两相位定义相同
        self.T = self.t_g_1 + self.t_g_2 + self.t_g_3 + self.t_g_4  # 周期


if __name__ == '__main__':
    a = Crossing2()
    print(a.v_bus)

